<?php
if(!defined('CORE_ROOT')) exit();
include(CORE_ROOT.'install/install.sql.php');
$dataversion = $db->get_by('value', 'settings', "variable='dataversion'");
if($dataversion === false)  $db->insert('settings', array('variable' => 'dataversion', 'value' => $sysedition));
if($dataversion < '4.1.3') {
	$db->addfield('categories', 'domain', 'varchar(255)');
}
if($dataversion < '4.1.7') {
	$db->addfield('categories', 'picture', 'varchar(255)');
}
if($dataversion < '4.2.2') {
	$db->addfield('items', 'aimurl', 'varchar(255)');
}
if($dataversion < '4.2.5') {
	$db->createtable('actions', $createtablesql['actions']);
	$db->addfield('items', 'draft', 'tinyint(4) default 0');
}
if($dataversion < '4.2.8') {
	$db->addfield('actions', 'value', 'tinyint(4) default 0');
}
if($dataversion < '5.0.1') {
	$db->createtable('apps', $createtablesql['apps']);
	$db->addfield('attachments', 'ispicture', 'tinyint(4) default 0');
	$db->addfield('items', 'string1', 'VARCHAR(255)');
	$db->addfield('items', 'string2', 'VARCHAR(255)');
	$db->addfield('items', 'string3', 'VARCHAR(255)');
	$db->addfield('items', 'string4', 'VARCHAR(255)');
	$plugins = readpathtoarray(AK_ROOT.'plugins');
	$templatepath = AK_ROOT."configs/apps/old_templateplugin/templateplugin/";
	foreach($plugins as $plugin) {
		if(is_dir($plugin)) continue;
		if(!is_readable($plugin)) continue;
		$filename = calfilenamefromurl($plugin);
		$filename = substr($filename, 0, -13).'.php';
		ak_copy($plugin, $templatepath.$filename);
	}
}
if($dataversion < '5.0.4') {
	$db->addfield('items', 'avgscore', 'VARCHAR(9)');
	$db->addfield('items', 'price', 'VARCHAR(9)');
}
setsetting('dataversion', $sysedition);
updatecache();
createfore();
?>